Handle from_utf8 new return type
authorDavid Davidović <geosoft.corp@gmail.com>
Wed, 24 Dec 2014 02:53:42 +0000 (03:53 +0100)
committerDavid Davidović <geosoft.corp@gmail.com>
Wed, 24 Dec 2014 03:53:03 +0000 (04:53 +0100)
As per rust-lang/rust@9b99436, the return type of from_utf8 has been
changed from Option to Result. Consequently, update code which relied on
this return type to work with Ok(...) and Err(...) instead of Some(...)
and None

src/cargo/ops/cargo_rustc/custom_build.rs
src/cargo/util/errors.rs
src/cargo/util/toml.rs

index 2445a6294295fe70e867bf4edf2c088e65d3597d..6da051f342952c48938ab54a020e11f341080999 100644 (file)
@@ -7,7 +7,7 @@ use std::sync::Mutex;
 
 use core::{Package, Target, PackageId, PackageSet};
 use util::{CargoResult, CargoError, human};
-use util::{internal, ChainError, Require};
+use util::{internal, ChainError};
 
 use super::job::Work;
 use super::{fingerprint, process, Kind, Context, Platform};
@@ -149,7 +149,7 @@ pub fn prepare(pkg: &Package, target: &Target, req: Platform,
         // This is also the location where we provide feedback into the build
         // state informing what variables were discovered via our script as
         // well.
-        let output = try!(str::from_utf8(output.output.as_slice()).require(|| {
+        let output = raw_try!(str::from_utf8(output.output.as_slice()).map_err(|_| {
             human("build script output was not valid utf-8")
         }));
         let parsed_output = try!(BuildOutput::parse(output, pkg_name.as_slice()));
index c33b7f1a7589bd4969899a188737fb1bbbd8cafe..7dedfa953565bd142dbd58d6088ae7d854d2df15 100644 (file)
@@ -157,18 +157,18 @@ impl ProcessError {
             Some(ref out) => {
                 let mut string = String::new();
                 match str::from_utf8(out.output.as_slice()) {
-                    Some(s) if s.trim().len() > 0 => {
+                    Ok(s) if s.trim().len() > 0 => {
                         string.push_str("\n--- stdout\n");
                         string.push_str(s);
                     }
-                    Some(..) | None => {}
+                    Ok(..) | Err(..) => {}
                 }
                 match str::from_utf8(out.error.as_slice()) {
-                    Some(s) if s.trim().len() > 0 => {
+                    Ok(s) if s.trim().len() > 0 => {
                         string.push_str("\n--- stderr\n");
                         string.push_str(s);
                     }
-                    Some(..) | None => {}
+                    Ok(..) | Err(..) => {}
                 }
                 Some(string)
             },
index a74cb1d80d87df72ff8ab582813e192dde8cb275..6320270b6e863334cb822d8a5f7ae0faba493fbd 100644 (file)
@@ -1,4 +1,5 @@
 use std::collections::HashMap;
+
 use std::fmt;
 use std::io::fs::{mod, PathExtensions};
 use std::os;
@@ -97,7 +98,7 @@ pub fn to_manifest(contents: &[u8],
         Some(path) => path,
         None => manifest,
     };
-    let contents = try!(str::from_utf8(contents).require(|| {
+    let contents = raw_try!(str::from_utf8(contents).map_err(|_| {
         human(format!("{} is not valid UTF-8", manifest.display()))
     }));
     let root = try!(parse(contents, &manifest));